1 /*
2 * File: Altitude_Mode.c
3 *
4 * Code generated for Simulink model 'Altitude_Mode'.
5 *
6 * Model version : 1.100
7 * Simulink Coder version : 8.5 (R2013b) 08-Aug-2013
8 * C/C++ source code generated on : Mon Feb 03 08:13:10 2014
9 *
10 * Target selection: ert.tlc
11 * Embedded hardware selection: 32-bit Embedded Processor
12 * Code generation objectives: Unspecified
13 * Validation result: Not run
14 */
15
16 #include "Altitude_Mode.h"
17 #include "Altitude_Mode_private.h"
18
19 /* Start for referenced model: 'Altitude_Mode' */
20 void Altitude_Mode_Start(rtB_Altitude_Mode *localB)
21 {
22 /* Start for Probe: '<S4>/Probe' */
23 localB->Probe[0U] = 0.025;
24 localB->Probe[1U] = 0.0;
25 }
26
27 /* Output and update for referenced model: 'Altitude_Mode' */
28 void Altitude_Mode(const real_T *rtu_AltRef, const real_T *rtu_Alt, const real_T
29 *rtu_AltRate, const real_T *rtu_TAS, const real_T *rtu_Theta,
30 const boolean_T *rtu_ALTMode, real_T *rty_ThetaCmd,
31 rtB_Altitude_Mode *localB, rtDW_Altitude_Mode *localDW)
32 {
33 /* local block i/o variables */
34 real_T rtb_UkYk1;
35 real_T rtb_Switch;
36 boolean_T rtb_NotALT;
37 real_T rtb_UnitConversion;
38 real_T rtb_Switch_o3ad;
39 real_T rtb_Sum3;
40 real_T rtb_Saturation;
41 real_T rtb_Saturation_krec;
42 real_T rtb_deltariselimit;
43 real_T rtb_deltafalllimit;
44 real_T rtb_Switch2;
45 real_T u;
46
47 /* Logic: '<Root>/Not ALT' */
48 rtb_NotALT = !(*rtu_ALTMode);
49
50 /* Switch: '<Root>/Switch' incorporates:
51 * Constant: '<Root>/ALT G limit'
52 * Constant: '<Root>/Other G limit'
53 */
54 if (rtb_NotALT) {
55 rtb_UnitConversion = 32.2;
56 } else {
57 rtb_UnitConversion = 6.44;
58 }
59
60 /* End of Switch: '<Root>/Switch' */
61
62 /* MinMax: '<Root>/MinMax' incorporates:
63 * Constant: '<Root>/Min TAS'
64 */
65 if ((*rtu_TAS) >= 100.0) {
66 rtb_Switch_o3ad = *rtu_TAS;
67 } else {
68 rtb_Switch_o3ad = 100.0;
69 }
70
71 /* End of MinMax: '<Root>/MinMax' */
72
73 /* Gain: '<S1>/Unit Conversion' incorporates:
74 * Product: '<Root>/Product'
75 */
76 rtb_UnitConversion = 57.295779513082323 * (rtb_UnitConversion /
77 rtb_Switch_o3ad);
78
79 /* Sum: '<Root>/Sum' */
80 localB->altError = (*rtu_AltRef) - (*rtu_Alt);
81
82 /* Lookup_n-D: '<Root>/Lookup Table' */
83 rtb_Sum3 = look1_binlag(localB->altError, rtCP_LookupTable_bp01Data,
84 rtCP_LookupTable_tableData, 7U);
85
86 /* Gain: '<S2>/Unit Conversion' incorporates:
87 * Product: '<Root>/Gamma Cmd'
88 * Sum: '<Root>/Sum1'
89 */
90 u = 57.295779513082323 * ((rtb_Sum3 - (*rtu_AltRate)) / rtb_Switch_o3ad);
91
92 /* Saturate: '<Root>/Saturation' */
93 if (u >= 20.0) {
94 rtb_Saturation = 20.0;
95 } else if (u <= (-20.0)) {
96 rtb_Saturation = (-20.0);
97 } else {
98 rtb_Saturation = u;
99 }
100
101 /* End of Saturate: '<Root>/Saturation' */
102
103 /* Sum: '<Root>/Sum3' */
104 rtb_Sum3 = (*rtu_Theta) - rtb_Saturation;
105
106 /* UnitDelay: '<S5>/X' */
107 rtb_Switch_o3ad = localDW->X_DSTATE;
108
109 /* Switch: '<S5>/Switch' */
110 if (rtb_NotALT) {
111 rtb_Switch_o3ad = rtb_Sum3;
112 }
113
114 /* End of Switch: '<S5>/Switch' */
115
116 /* Saturate: '<S5>/Saturation' */
117 if (rtb_Switch_o3ad >= 20.0) {
118 rtb_Saturation_krec = 20.0;
119 } else if (rtb_Switch_o3ad <= (-20.0)) {
120 rtb_Saturation_krec = (-20.0);
121 } else {
122 rtb_Saturation_krec = rtb_Switch_o3ad;
123 }
124
125 /* End of Saturate: '<S5>/Saturation' */
126
127 /* Sum: '<S4>/Difference Inputs1' incorporates:
128 * Sum: '<Root>/Sum2'
129 * UnitDelay: '<S4>/Delay Input2'
130 */
131 rtb_UkYk1 = (rtb_Saturation + rtb_Saturation_krec) -
132 localDW->DelayInput2_DSTATE;
133
134 /* Product: '<S4>/delta rise limit' */
135 rtb_deltariselimit = rtb_UnitConversion * localB->Probe[0];
136
137 /* Product: '<S4>/delta fall limit' incorporates:
138 * Gain: '<Root>/negate'
139 */
140 rtb_deltafalllimit = ((-1.0) * rtb_UnitConversion) * localB->Probe[0];
141
142 /* Switch: '<S6>/Switch' incorporates:
143 * RelationalOperator: '<S6>/UpperRelop'
144 */
145 if (rtb_UkYk1 < rtb_deltafalllimit) {
146 rtb_Switch = rtb_deltafalllimit;
147 } else {
148 rtb_Switch = rtb_UkYk1;
149 }
150
151 /* End of Switch: '<S6>/Switch' */
152
153 /* Switch: '<S6>/Switch2' incorporates:
154 * RelationalOperator: '<S6>/LowerRelop1'
155 */
156 if (rtb_UkYk1 > rtb_deltariselimit) {
157 rtb_Switch2 = rtb_deltariselimit;
158 } else {
159 rtb_Switch2 = rtb_Switch;
160 }
161
162 /* End of Switch: '<S6>/Switch2' */
163
164 /* Sum: '<S4>/Difference Inputs2' incorporates:
165 * UnitDelay: '<S4>/Delay Input2'
166 */
167 *rty_ThetaCmd = rtb_Switch2 + localDW->DelayInput2_DSTATE;
168
169 /* Switch: '<S5>/Switch1' */
170 if (rtb_NotALT) {
171 /* Update for UnitDelay: '<S5>/X' */
172 localDW->X_DSTATE = rtb_Sum3;
173 } else {
174 /* Update for UnitDelay: '<S5>/X' incorporates:
175 * Product: '<S5>/Product1'
176 * Sum: '<S5>/Sum'
177 */
178 localDW->X_DSTATE = (Altitude_Mode_ConstB.Product * rtb_Saturation) +
179 rtb_Saturation_krec;
180 }
181
182 /* End of Switch: '<S5>/Switch1' */
183
184 /* Update for UnitDelay: '<S4>/Delay Input2' */
185 localDW->DelayInput2_DSTATE = *rty_ThetaCmd;
186 }
187
188 /* Model initialize function */
189 void Altitude_Mode_initialize(rtB_Altitude_Mode *localB, rtDW_Altitude_Mode
190 *localDW)
191 {
192 /* Registration code */
193
194 /* block I/O */
195 (void) memset(((void *) localB), 0,
196 sizeof(rtB_Altitude_Mode));
197
198 /* states (dwork) */
199 (void) memset((void *)localDW, 0,
200 sizeof(rtDW_Altitude_Mode));
201 }
202
203 /*
204 * File trailer for generated code.
205 *
206 * [EOF]
207 */
208
|